from treenode import predg_ancestors, list_to_tree


def lowestCommonAncestor(root, p, q):
    if root in (None, p, q):
        return root
    left = lowestCommonAncestor(root.left, p, q)
    right = lowestCommonAncestor(root.right, p, q)
    return right if left is None else left if right is None else root


if __name__ == '__main__':
    root = list_to_tree([3,5,1,6,2,0,8,None,None,7,4])
    print(predg_ancestors(root, 5))
